package com.faxsun.core.persist.entity;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;
import org.springframework.util.StringUtils;

@Entity
@Table(name = "fx_live")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class LivePO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6909451106023201556L;

	/**
	 * 精选频道
	 */
	public static final boolean SELECTED = Boolean.TRUE;
	/**
	 * 非精选频道
	 */
	public static final boolean UNSELECTED = Boolean.FALSE;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;

	private String topic;

	private Date startTime;

	private Date endTime;

	@Column(name = "cover_image")
	private String coverImage;

	@Column(name = "description")
	private String description = "Hi，世界那么大，不想去看看吗？范客生活带给您完美的直播和互动体验，记录生活和工作中每一个值得回忆的时刻。Enjoy:)";

	@Type(type = "org.hibernate.type.NumericBooleanType")
	private boolean isSelected;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getTopic() {
		return topic;
	}

	public void setTopic(String topic) {
		this.topic = topic;
	}

	public Date getStartTime() {
		return startTime;
	}

	public String getStartTimeString() {
		String ret = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startTime);
		return ret;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public String getEndTimeString() {
		String ret = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(endTime);
		return ret;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getCoverImage() {
		if (StringUtils.isEmpty(coverImage)
				|| (!this.coverImage.startsWith("http://") && !this.coverImage.startsWith("https://"))) {
			// 图片不存在或图片非绝对路径，则使用默认图片
			coverImage = "http://image.faxsun.com/default/live/default.png";
		}
		return coverImage;
	}

	public void setCoverImage(String coverImage) {
		this.coverImage = coverImage;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}
}
